
//Copyright 1997-2009 Syrinx Development, Inc.
//This file is part of the Syrinx Web Application Framework (SWAF).
// == BEGIN LICENSE ==
//
// Licensed under the terms of any of the following licenses at your
// choice:
//
//  - GNU General Public License Version 3 or later (the "GPL")
//    http://www.gnu.org/licenses/gpl.html
//
//  - GNU Lesser General Public License Version 3 or later (the "LGPL")
//    http://www.gnu.org/licenses/lgpl.html
//
//  - Mozilla Public License Version 1.1 or later (the "MPL")
//    http://www.mozilla.org/MPL/MPL-1.1.html
//
// == END LICENSE ==
using System;
using System.Collections;
using System.Data;
using System.Text.RegularExpressions;
using System.Xml;


using Swaf;
using Swaf.BizObj;


namespace Swaf.DataAccess
{
	/// <summary>
	/// Summary description for AdoNetIntFormatter.
	/// </summary>
	public class AdoNetIntFormatter : IDataFormatter
	{
		protected AdoNetDataResponse m_resp;
		protected string m_intColName;
		protected IApplication m_app;

		public AdoNetIntFormatter(Match mr, object[] extraInfo)
		{
			if(extraInfo != null && extraInfo.Length > 0 && extraInfo[0] is AdoNetDataResponse)
			{
				m_resp = (AdoNetDataResponse)extraInfo[0];
				m_app = Application.currentApp;

				m_intColName = mr.Groups[1].Value;
			}
		}
		#region IDataFormatter Members

		public object format()
		{
			object o = null;
			try 
			{
				IDataReader reader = m_resp.Reader;
				if(reader != null && reader.Read())
				{
					o = reader.GetValue(reader.GetOrdinal(m_intColName));
				}
			}
			catch(Exception e)
			{
				throw new DataFormatException("int", m_intColName, e);
			}
			
			return o;
		}

		#endregion
	}
}
